#!/usr/bin/perl -w

use strict;
use LWP::Simple;
use XML::XPath;
use XML::XPath::XMLParser;
use SOAP::Transport::HTTP;

SOAP::Transport::HTTP::CGI
  -> dispatch_to('srv')
  -> handle;

package srv;

sub buscar_noticia {
  shift; #el primer parametro es el namespace, ya podria decirlo en algun lado.
  my @urls;
  my $palabra =  lc shift;
  my $documento = LWP::Simple::get ('http://www.elpais.com/rss/feed.html?feedId=1022');
  my $xp = XML::XPath->new(xml=>$documento);
  my $nodos = $xp->find ('//item');
  foreach my $nodo ($nodos->get_nodelist) {
    my $titulo = lc $nodo->getChildNode(2)->string_value ;
    if ($titulo =~ m/$palabra/g){
      push @urls, $nodo->getChildNode(4)->string_value;
    }
  }
  return @urls;
}
